/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.File;
import javax.swing.JDialog;

/**
 *
 * @author ARMGARCES
 */
public class FileChooser extends javax.swing.JDialog {
    private File file;
    private static VentanaArchivo pantalla;
    private int ancho  = 600;
    private int alto   = 400;
    /**
     * Creates new form FileChooser
     * @param parent
     * @param modal  
     */
    public FileChooser(java.awt.Frame parent, boolean modal) {
        super(parent, modal); 
        pantalla = (VentanaArchivo) parent;
        initComponents();
        this.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentHidden(ComponentEvent e) {
                salir();
                ((JDialog)(e.getComponent())).dispose();
            }
        });
    }
    /**
     * 
     * @return 
     */
    public File getFile(){
        return file;
    }
    /**
     * 
     */
    public void centrarVentana(){
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        this.setSize(ancho,alto);

        int x = (screenSize.width  -  this.getWidth()) / 2;
        int y = (screenSize.height - this.getHeight()) / 2;
        this.setLocation(x, y);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jFileChooser1.setControlButtonsAreShown(false);
        jFileChooser1.setCurrentDirectory(new java.io.File("\\\\192.168.1.9\\Cobranza\\Seniat"));
        jFileChooser1.setMaximumSize(null);
        jFileChooser1.setMinimumSize(null);
        jFileChooser1.setPreferredSize(new java.awt.Dimension(600, 400));
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jFileChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jFileChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
        // TODO add your handling code here:
        salir();
    }//GEN-LAST:event_jFileChooser1ActionPerformed

    private void salir(){
        if (jFileChooser1.getSelectedFile() != null) {
            file = jFileChooser1.getSelectedFile();
        }else{
            file = null;
        }
        pantalla.updateFile(file);
        this.dispose();
    }
    /**
     * @param args the command line arguments
     */
 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables
}
